# Contributor: Runar Tenfjord < runar dot tenfjord at gmail dot com >

_realname=pandas
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}" "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=0.18.0
pkgrel=2
pkgdesc="Cross-section and time series data analysis toolkit (mingw-w64)"
arch=('any')
url="http://pandas.pydata.org/"
license=('BSD')
makedepends=("${MINGW_PACKAGE_PREFIX}-python2-numpy"
             "${MINGW_PACKAGE_PREFIX}-python3-numpy"
             "${MINGW_PACKAGE_PREFIX}-python2-pytz"
             "${MINGW_PACKAGE_PREFIX}-python3-pytz"
             "${MINGW_PACKAGE_PREFIX}-python2-dateutil"
             "${MINGW_PACKAGE_PREFIX}-python3-dateutil"
             "${MINGW_PACKAGE_PREFIX}-python2-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python3-setuptools"
             "${MINGW_PACKAGE_PREFIX}-gcc")
source=("https://pypi.python.org/packages/source/p/pandas/${_realname}-${pkgver}.tar.gz")
sha256sums=('c975710ce8154b50f39a46aa3ea88d95b680191d1d9d4b5dd91eae7215e01814')


prepare() {
  cp -a ${_realname}-${pkgver} ${_realname}-py2-${pkgver}
  cp -a ${_realname}-${pkgver} ${_realname}-py3-${pkgver}

  cd ${_realname}-py2-${pkgver}
  sed -e "s|#![ ]*/usr/bin/python$|#!/usr/bin/python2|" \
    -e "s|#![ ]*/usr/bin/env python$|#!/usr/bin/env python2|" \
    -e "s|#![ ]*/bin/env python$|#!/usr/bin/env python2|" \
    -i $(find . -name '*.py')
}

build() {
  # build for python2
  cd ${srcdir}/${_realname}-py2-${pkgver}
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py build_ext --inplace

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py build

  # build for python3
  cd ${srcdir}/${_realname}-py3-${pkgver}
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py build_ext --inplace

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py build
}

package_python2-pandas() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2-numpy"
           "${MINGW_PACKAGE_PREFIX}-python2-pytz"
           "${MINGW_PACKAGE_PREFIX}-python2-dateutil"
           "${MINGW_PACKAGE_PREFIX}-python2-setuptools")
  optdepends=("${MINGW_PACKAGE_PREFIX}-python2-scipy: needed for miscellaneous statistical functions"
              "${MINGW_PACKAGE_PREFIX}-python2-matplotlib: needed for plotting"
              "${MINGW_PACKAGE_PREFIX}-python2-numexpr: needed for accelerating certain numerical operations (recommended)"
              "${MINGW_PACKAGE_PREFIX}-python2-openpyxl: needed for reading/writing Excel file")

  cd ${_realname}-py2-${pkgver}
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py install --skip-build \
    --prefix=${MINGW_PREFIX} --root=${pkgdir} --optimize=1

  install -Dm644 LICENSE \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/python2-${_realname}/LICENSE"
}

package_python3-pandas() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3-numpy"
           "${MINGW_PACKAGE_PREFIX}-python3-pytz"
           "${MINGW_PACKAGE_PREFIX}-python3-dateutil"
           "${MINGW_PACKAGE_PREFIX}-python3-setuptools")
  optdepends=("${MINGW_PACKAGE_PREFIX}-python3-scipy: needed for miscellaneous statistical functions"
              "${MINGW_PACKAGE_PREFIX}-python3-matplotlib: needed for plotting"
              "${MINGW_PACKAGE_PREFIX}-python3-numexpr: needed for accelerating certain numerical operations (recommended)"
              "${MINGW_PACKAGE_PREFIX}-python3-openpyxl: needed for reading/writing Excel file")

  cd ${_realname}-py3-${pkgver}
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --skip-build \
    --prefix=${MINGW_PREFIX} --root=${pkgdir} --optimize=1

  install -Dm644 LICENSE \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/python3-${_realname}/LICENSE"
}

package_mingw-w64-i686-python2-pandas() {
  package_python2-pandas
}

package_mingw-w64-i686-python3-pandas() {
  package_python3-pandas
}

package_mingw-w64-x86_64-python2-pandas() {
  package_python2-pandas
}

package_mingw-w64-x86_64-python3-pandas() {
  package_python3-pandas
}
